package com.didd.core.message.dingtalk.entity;

import cn.hutool.core.util.StrUtil;
import com.didd.core.message.dingtalk.type.MessageType;
import lombok.Builder;

import java.util.HashMap;
import java.util.Map;

/**
 * 链接消息类型
 *
 * @author diddd
 * @version 1.0.0
 */
@Builder
public class LinkMessage extends BaseMessage {

    /**
     * 消息简介
     */
    private String text;

    /**
     * 消息标题
     */
    private String title;

    /**
     * 封面图片URL
     */
    private String picUrl;

    /**
     * 消息跳转URL
     */
    private String messageUrl;

    @Override
    public Map toMessageMap() {

        if (StrUtil.isEmpty(this.messageUrl) || StrUtil.isEmpty(this.title) ||
                StrUtil.isEmpty(this.text)) {
            throw new IllegalArgumentException("please check the necessary parameters!");
        }

        HashMap<String, Object> resultMap = new HashMap<>(8);
        resultMap.put("msgtype", MessageType.link);

        HashMap<String, String> linkItems = new HashMap<>(8);
        linkItems.put("title", this.title);
        linkItems.put("text", this.text);
        linkItems.put("picUrl", this.picUrl);
        linkItems.put("messageUrl", this.messageUrl);
        resultMap.put("link", linkItems);

        return resultMap;
    }
}